package logic

import (
	"context"
	"month2/B/rpc_B/user"

	"month2/B/api_B/internal/svc"
	"month2/B/api_B/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGoodsAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsAddLogic {
	return &GoodsAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GoodsAddLogic) GoodsAdd(req *types.GoodsAddRequest) (resp *types.Response, err error) {
	add, err := l.svcCtx.BRpc.GoodsAdd(l.ctx, &user.GoodsAddRequest{
		GoodsName:  req.GoodsName,
		GoodsPrice: float32(req.GoodsPrice),
		GoodsNum:   int64(req.GoodsNum),
		GoodsImg:   req.GoodsImg,
		Status:     int64(req.Status),
	})
	if err != nil {
		return &types.Response{
			Msg:  "产品发布失败",
			Data: nil,
			Code: 500,
		}, nil
	}
	return &types.Response{
		Msg:  "产品发布成功",
		Data: add,
		Code: 200,
	}, nil
}
